package com.tencent.crazypenguin.action;

import com.opensymphony.xwork2.ActionSupport;
import com.tencent.crazypenguin.bean.MUser;
import com.tencent.crazypenguin.bean.MatchList;
import com.tencent.crazypenguin.config.HbmUtil;
import com.tencent.crazypenguin.config.ResultType;

import net.sf.json.JSONObject;

public class GoHome extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5866783778174873436L;
	
	private String result;

	@Override
	public String execute() throws Exception {
		JSONObject rspData = new JSONObject();
		try {
			JSONObject authData = HbmUtil.getAuthDate();
			long userId = authData.getLong("userId");
			MUser mUser = new MUser(authData.getJSONObject("origin").getDouble("latitude"),authData.getJSONObject("origin").getDouble("longitude"),
					authData.getJSONObject("target").getDouble("latitude"),authData.getJSONObject("target").getDouble("longitude"));
			
			MatchList.addMuser(userId, mUser);
			
			rspData.put("resultCode", ResultType.SUCEESS);
			result = rspData.toString();
			return "done";
			
		} catch (Exception e) {
			e.printStackTrace();
			rspData.clear();
			rspData.put("resultCode", ResultType.EXCEPTION);
			result = rspData.toString();
			return "done";
		}
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}
	
	

}
